<?php

namespace App\Models\Flaw;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Task extends Model
{
    //使用软删除
    use SoftDeletes;
    //关联表
    protected  $table = 'task';
    //软删除自动维护字段,不为空时此条数据不显示
    protected $dates = ['deleted_at'];

    //获取列表信息
    public static function getList (){
        $sel = ['task.id','task.sendtype','task.appid','task.created_at','task.updated_at','v.id as vulsid','v.vuls_number','v.status','task.level_name','task.deadline','task.appname','task.useremail','task.user','v.title','v.description','v.level_id','v.check_at as send_time','v.delayed_at'];
        return self::select($sel)->join('vuls as v',function($join){
            $join->on('task.vulsid','=','v.id');
        })->get();
    }

    /**
     * @param $app
     * @param $vulsId
     * @return bool
     */
    public static function resetApp($app,int $vulsId){
        if (is_int($app))
            $appId = $app;
        elseif ( is_object($app))
            $appId = $app->id;
        elseif(is_string($app))
            $appId = intval($app);
        else
            return false;
        $where =['vulsid'=>$vulsId];
        $task = self::where($where)->first();
        // return self::where($where)->update(['appid'=>$appId]);
        if ($task){
            $task->appid = $appId;
            return $task->save();
        }
        return true;
    }
}
